<?php

use Hyperf\Database\Schema\Schema;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Migrations\Migration;

class CreateBroadcastDevicesTable extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('broadcast_devices', function (Blueprint $table) {
            $table->comment('广播设备管理表');
            $table->bigIncrements('id')->comment('主键ID');
            $table->string('device_name', 64)->nullable()->comment('设备名称');
            $table->string('device_model', 64)->nullable()->comment('设备型号');
            $table->string('device_brand', 64)->nullable()->comment('设备品牌');
            $table->string('device_sn', 64)->nullable()->comment('设备序列号');
            $table->float('longitude', 8, 2)->nullable()->comment('经度');
            $table->float('latitude', 8, 2)->nullable()->comment('纬度');
            $table->float('altitude', 8, 2)->nullable()->comment('海拔高度');
            $table->string('ip_address', 128)->nullable()->comment('IP地址');
            $table->integer('port')->nullable()->comment('端口号');
            $table->string('secret', 64)->nullable()->comment('密钥');
            $table->string('mac_address', 64)->nullable()->comment('MAC地址');
            $table->tinyInteger('online_status')->default(0)->comment('在线状态：1-离线，2-在线');
            $table->timestamp('last_online_time')->nullable()->comment('最后在线时间');
            $table->string('device_group', 100)->nullable()->comment('设备分组');
            $table->tinyInteger('maintenance_status')->default(1)->comment('维护状态：1-正常，2-需要维护，3-维护中，4-报废');
            $table->text('remark')->nullable()->comment('备注');
            
            // 索引
            $table->index('device_name', 'idx_device_name');
            $table->index('online_status', 'idx_online_status');
            $table->index('device_group', 'idx_device_group');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('broadcast_devices');
    }
}